//
// Created by chaseaishang on 23-5-10.
//

#pragma once
#include "test.h"
#include "Render/VertexBuffer.h"
#include "Render/VertexBufferLayout.h"
#include "Render/Texture.h"
#include "Camera.h"
#include "Render/SpriteRenderer.h"
#include "GameLevel.h"
#include "BallObject.h"
#include <memory>
#include "GameTools/Portocol.h"
namespace test {
    enum GameState
    {
        GAME_ACTIVE,
        GAME_MENU,
        GAME_WIN,
        GAME_READY,
    };
    class Game1 : public Test
    {
    public:
        Game1();
        virtual ~Game1();

        virtual void OnUpdate(float deltaTime)override;
        virtual void OnEvent(Event& e)override;
        virtual void OnRender()override;
        virtual void OnImGuiRender() override;
        // debug
        float get_ball_pos_x();
        float get_other_pos_x();
        int win=0;
        bool master;
    private:
        //webIO
        std::unique_ptr<Portocol>m_portocol;
        // game
        int                 Width, Height;
        std::vector<GameLevel> Levels;
        std::unique_ptr<GameObject> Player;
        std::unique_ptr<GameObject> other_Player;
        std::unique_ptr<BallObject> Ball;
        int                 Level;
        bool succeed;

        void DoCollisions();
        void Collision_Player_Ball(GameObject&,BallObject&);
        bool is_failed();
        void Reset();
        //render
        std::unique_ptr<VertexArray> m_VAO;
        std::unique_ptr<IndexBuffer> m_IndexBuffer;
        std::unique_ptr<VertexBuffer> m_VertexBuffer;
        std::unique_ptr<Shader> m_Shader;
        std::unique_ptr<Texture> m_Texture;
        std::unique_ptr<SpriteRenderer> m_SpriteRenderer;
//SpriteRenderer
        glm::mat4 m_Proj, m_View;
        float m_rotate;
        glm::vec3 m_TranslationA, m_TranslationB;




        OrthographicCameraController camera{0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f,0};
    private://for game
        GameState State;
    };
}






